<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
  String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>修改客户信息</title>
<link href="<%=path1%>/css/css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.src.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/i18n/grid.locale-cn.js"></script>
<script type="text/javascript" src="<%=path1%>/scripts/pagekage/utils/widget/jqGrid/jquery.jqGrid.min.js"></script>

<!--[if IE 6]>
<script type="text/javascript" src="js/ie6png.js" ></script>
<script type="text/javascript">
DD_belatedPNG.fix('div,ul,li,a,p,img,body,dl,dt,dd');</script>
<![endif]-->
<script type="text/javascript">
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
</script>
<script>
<!--
/*第一种形式 第二种形式 更换显示样式*/
function setTab(name,cursel,n){
for(i=1;i<=n;i++){
var menu=document.getElementById(name+i);
var con=document.getElementById("con_"+name+"_"+i);
menu.className=i==cursel?"hover":"";
con.style.display=i==cursel?"block":"none";
}
}
//-->
</script>
<script type="text/javascript">
   function checkcustomer_name(){
	  var customer_name= $("#customer_name").val();
	  if(customer_name==""){
		 alert("客户名称不能为空！"); 
		 $("#customer_name").focus();
		 return false;
	  }
	  return true;
   }
   function checkPhone(){
	   var phone=$("#tel").val();
	   if(phone==""){
		   alert("联系电话不能为空");
		   $("#tel").focus();
		   return false;
	   }
	   return true;
   }
   function Phone(){
	   var tel=$("#tel").val();
	   var phone=/^1\d{10}$/;
	   var mobile=/^0\d{2,3}-?\d{7,8}$/;
	   if (phone.test(tel) || mobile.test(tel)) { 
		      //alert("号码正确~"); 
		 }else{ 
		      alert("号码有误~"); 
		      $("#tel").focus();
		 };
   }
/*   function paperstNo(){
	   var no=$("#paperstNo").val();
	   var paperstNo=/^\d{17}([0-9]|X)$/;
	   if (paperstNo.test(no)) { 
		      //alert("身份证号码正确~"); 
		 }else{ 
		      alert("身份证号码有误~"); 
		      $("#paperstNo").focus();
		 };
   }
   */
</script>
<!-- 查询要修改的记录  并显示到表单中 -->
<script type="text/javascript">
$(document).ready(function(){
	var SeachSql;
	var id;
    var str=window.location.href; //得到listclient的地址
    //alert("str"+str);
    var es=/id=/; 
    es.exec(str); //得到地址后面变量名称
    //alert("es--"+es.exec(str));
    var right=RegExp.rightContext;//得到地址后面变量名称的值
    //alert("right-"+right);

    id=right;//将结果赋值给id
    
    if(id!="" )
	  {
    	//alert(id);
    	customer_id =id;
    	alert(customer_id);
	  }
    //alert(SearchSql);
    //$.jqGrid('setGridParam',{ 
    	//url:"/wangda/client/select.do",
       // datatype:'json', 
       // postData:{'pageSize':10,'pageIndex':1,'Search':SearchSql}, // 发送数据   
       // page:1 
    //}).trigger("reloadGrid"); 
     return select();  
});

function select(){
	//alert("123");
	//alert("ceach:"+SearchSql);
	$.ajax({
    	url:"./Customer/selectById.do",
        datatype:'json', 
        data:{'customer_id':customer_id}, // 发送数据   
        error:function(data){  
            alert("出错了,没有这个客户！！");  
       },  
       success:function(data){
       	//alert('客户信息查询成功！');
       	//window.location.href = 'listclient.jsp'; 
       	//alert(data);
       	//console.log("---------"+data);
       //	alert("namber:"+data.rows.length);
       	alert( data.rows[0].customer_id);
       	alert( data.rows[0].customer_name);
       	$("#customer_id").val(data.rows[0].customer_id),
       	$("#customer_name").val(data.rows[0].customer_name),
		$("#tel").val(data.rows[0].tel);
		if(data.rows[0].sex=='男'){
			 $("input:radio[name='sex']").eq(0).attr("checked",true);
		     //$("input[name=sex]").attr("checked","checked");
		     // $("#sex").attr("checked",'checked');
		     //$("#sex").removeAttr("checked");
		}else{
			$("input:radio[name='sex']").eq(1).attr("checked",true);
			//$("input[name=sex]").attr("checked","checked");
		    //$("#sex").attr("checked",'checked');
		    //$("#sex").removeAttr("checked");
		}
		if(data.rows[0].customer_type=='个人'){
			$("input:radio[name='customer_type']").eq(0).attr("checked",true);
		}
		else{
			$("input:radio[name='customer_type']").eq(1).attr("checked",true);
		}
		
		$("#describel").val(data.rows[0].describel),
		$("#maritalStatus").val(data.rows[0].marital_status),
		$("#id_number").val(data.rows[0].id_number),
		$("#address").val(data.rows[0].address),
		$("#profession").val(data.rows[0].profession),
		$("#income_level").val(data.rows[0].income_level)
       	//var model=data.model;
       }
 
        });
}
</script>

<!-- 得到修改的值  修改后跳回显示页 -->
<script type="text/javascript">
    function ajaxUpdate(){
    	//alert("123");
    	//alert("id---"+$("#id").val());
    
    	
    	alert($("#customer_id").val());
        $.ajax({ 	
        data: {
        	customer_id:$("#customer_id").val(),
        	customer_name:$("#customer_name").val(),
        	tel:$("#tel").val(),
        	sex:$("input[name='sex']:checked").val(),
        	customer_type:$("input[name='customer_type']:checked").val(),
        	describel:$("#describel").val(),
        	maritalStatus:$("#maritalStatus").val(),
        	address:$("#address").val(),
        	id_number:$("#id_number").val(),
        	profession:$("#profession").val(),
        	income_level:$("#income_level").val()
        },
        type:"Post",  
        dataType: 'json',  
        url:"./Customer/updateCustomer.do", 
        error:function(data){  
             alert("修改出错了！！");  
        },  
        success:function(data){
        	alert('修改成功！');
        	window.location.href = 'listCustomer.jsp'; 
         }  
         });  
     } 
    // 重置
    function ajaxReset(){
    	$("#customer_name").val("");
    	$("#phone").val("");
    	$("input:radio[name='sex']").eq(0).attr("checked",true);
    	$("input:radio[name='clientType']").eq(0).attr("checked",true);
    	$("#paperstType").val("");
		$("#paperstNo").val("");
		$("#eduStatus").val("");
		$("#profession").val("");
		$("#income").val("");
		$("#maritalStatus").val("");
		$("#address").val("");
    }
</script>
</script>
</head>
<body>
<div class="yboxwidth boxcenter">
  <div class="ybox09">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
       <td style="padding-left: 20px"><table border="0" cellspacing="0" cellpadding="0">
          <tr valign="top" >
            <td class="ybox11td5" ></td>
            <td class="ybox11td6" >修改客户信息</td>
            <td class="ybox11td7"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td3"></td>
            <td class="ybox11td2"></td>
            <td class="ybox11td4"></td>  
          </tr>
        </table></td>
        </tr>
    </table>
  </div>
  <div class="ybox02">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="margb4">
      <tr>
        <td class="ybox03td1"></td>
        <td class="ybox03td2"></td>
        <td class="ybox03td3"></td>
      </tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
            <dl>
              <dt><strong>基本信息</strong> </dt>
            </dl>
            <input type="hidden" id="customer_id"  name="customer_id"/>
          </div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox04table">
            <tr>
              <td width="15%" class="ybox04tdl"><span class="red">*</span>客户名称</td>
              <td width="18%" class="ybox04tdr"><input id="customer_name" name="customer_name"type="text"  class="black12" style="width:90%;"  /></td>
              <td width="15%" class="ybox04tdl"><span class="red">*</span> 联系电话</td>
              <td width="18%" class="ybox04tdr"><input name="tel" type="text"  class="black12" id="tel" style="width:90%;" onblur="Phone()"/></td>
              <td width="15%" class="ybox04tdl"> 性别</td>
              <td width="18%" class="ybox04tdr">
                  <input type="radio" name="sex" value="男"/>男 &nbsp;&nbsp;&nbsp;
                  <input type="radio" name="sex" value="女"/>女
              </td>
            </tr>
          </table></td>
        <td class="ybox03td6"></td>
      </tr>
     <tr height="20" ><td colspan="6" bgcolor="#e9f7ff"></td></tr>
      <tr>
        <td class="ybox03td4"></td>
        <td class="ybox03td5"><div class="ybox05 margb8">
            <dl>
              <dt><strong>详细信息</strong> </dt>
            </dl>
          </div>
          <table width="100%" border="0" cellpadding="0" cellspacing="1" class="ybox04table">
            <tr>
            <td width="15%" class="ybox04tdl"> 客户类型</td>
            <td width="18%" class="ybox04tdr">
                <input type="radio" name="customer_type"  value="个人"/>个人
                <input type="radio" name="customer_type"  value="公司"/>公司
            </td>
            <td width="15%" class="ybox04tdl"> 证件类型</td>
              <td width="18%" class="ybox04tdr">
                 <select name="paperstType" id="paperstType">
                    <option value="身份证">身份证</option>
                    <option value="汽车证">汽车证</option>
                    <option value="学生证">学生证</option>
                 </select>
              </td> 
              <td width="15%" class="ybox04tdl">证件号码 </td>
              <td width="18%" class="ybox04tdr"><input name="id_number" type="text"  class="black12" id="id_number" style="width:90%;" onblur="paperstNo()"/></td>    
            </tr>
             
            <tr>
              <td width="15%" class="ybox04tdl">描述</td>
              <td width="18%" class="ybox04tdr"><input name="describel" type="text"  class="black12" id="describel" style="width:90%;" /></td>
              <td width="15%" class="ybox04tdl"> 职业</td>
              <td width="18%" class="ybox04tdr"><input name="profession" type="text"  class="black12" id="profession" style="width:90%;"  /></td>
              <td width="15%" class="ybox04tdl"> 收入层次</td>
              <td width="18%" class="ybox04tdr"><input name="income_level" type="text"  class="black12" id="income_level" style="width:90%;"  /></td>
              
            </tr>
            <tr>
            <td width="15%" class="ybox04tdl"> 婚姻状况</td>
              <td width="18%" class="ybox04tdr"><input name="maritalStatus" type="text"  class="black12" id="maritalStatus" style="width:90%;"  /></td>
              
              <td  class="ybox04tdl"> 通讯地址</td>
              <td width="18%" colspan="4" class="ybox04tdr"><input name="address" type="text"  class="black12" id="address" style="width:96%;"  /></td>
            </tr>
            <tr>
            <td width="18%" colspan="6" class="ybox04tdr">
              
               <dl>
                 <dt><strong>【注】</strong> 
                 1.基本信息为必填项</br>
                 2.详细信息必须在用户下订单之前填写完整
              </dt>
               </dl>
            </td>
            </tr>
            
          </table></td>
        <td class="ybox03td6"></td>
      </tr>
      <tr>
        <td class="ybox03td7"></td>
        <td class="ybox03td8"></td>
        <td class="ybox03td9"></td>
      </tr>
    </table>
    <table width="380" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="60" align="center"><img src="images/bottoncommit.gif" width="95" height="34" style="cursor: pointer;" onclick="return checkcustomer_name()&& checkPhone()&&ajaxUpdate()" /></td>
        <td height="60" align="center"><img src="images/bottonreset.gif" width="95" height="34" style="cursor: pointer;" onclick="ajaxReset()"/></td>
      </tr>
    </table>
  </div>
</div>
</body>
</html>
